<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Construct a new Binary</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="class.mongodb-bson-binary.html">« MongoDB\BSON\Binary</a></li>
      <li style="float: right;"><a href="mongodb-bson-binary.getdata.html">MongoDB\BSON\Binary::getData »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.mongodb-bson-binary.html">MongoDB\BSON\Binary</a></li>
    <li>Construct a new Binary</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="mongodb-bson-binary.construct" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">MongoDB\BSON\Binary::__construct</h1>
  <p class="verinfo">(mongodb &gt;=1.0.0)</p><p class="refpurpose"><span class="refname">MongoDB\BSON\Binary::__construct</span> &mdash; <span class="dc-title">Construct a new Binary</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-mongodb-bson-binary.construct-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">final</span> <span class="modifier">public</span> <span class="methodname"><strong>MongoDB\BSON\Binary::__construct</strong></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$data</code></span>, <span class="methodparam"><span class="type">int</span> <code class="parameter">$type</code><span class="initializer"> = MongoDB\BSON\Binary::TYPE_GENERIC</span></span>)</div>

 </div>


 <div class="refsect1 parameters" id="refsect1-mongodb-bson-binary.construct-parameters">
  <h3 class="title">参数</h3>
  <dl>
   
    <dt>
<code class="parameter">data</code> (<span class="type">string</span>)</dt>

    <dd>

     <p class="para">
      Binary data.
     </p>
    </dd>

   
   
    <dt>
<code class="parameter">type</code> (<span class="type">int</span>)</dt>

    <dd>

     <p class="para">
      Unsigned 8-bit integer denoting the data&#039;s type. Defaults to <strong><code>MongoDB\BSON\Binary::TYPE_GENERIC</code></strong> if not specified.
     </p>
    </dd>

   
  </dl>

 </div>


 <div class="refsect1 errors" id="refsect1-mongodb-bson-binary.construct-errors">
  <h3 class="title">错误／异常</h3>
  <ul class="simplelist">
   <li class="member">Throws <span class="classname"><a href="class.mongodb-driver-exception-invalidargumentexception.html" class="classname">MongoDB\Driver\Exception\InvalidArgumentException</a></span> on argument parsing errors.</li>
   <li class="member">Throws <span class="classname"><a href="class.mongodb-driver-exception-invalidargumentexception.html" class="classname">MongoDB\Driver\Exception\InvalidArgumentException</a></span> if <code class="parameter">type</code> is not an unsigned 8-bit integer.</li>
   <li class="member">Throws <span class="classname"><a href="class.mongodb-driver-exception-invalidargumentexception.html" class="classname">MongoDB\Driver\Exception\InvalidArgumentException</a></span> if <code class="parameter">type</code> is <strong><code>MongoDB\BSON\Binary::TYPE_UUID</code></strong> or <strong><code>MongoDB\BSON\Binary::TYPE_OLD_UUID</code></strong> and <code class="parameter">data</code> is not exactly 16 bytes in length.</li>
  </ul>
 </div>


 <div class="refsect1 changelog" id="refsect1-mongodb-bson-binary.construct-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>PECL mongodb 1.15.0</td>
       <td>
        <p class="para">
         The <code class="parameter">type</code> parameter defaults to
         <strong><code>MongoDB\BSON\Binary::TYPE_GENERIC</code></strong> if not specified.
        </p>
       </td>
      </tr>

      <tr>
       <td>PECL mongodb 1.3.0</td>
       <td>
        <p class="para">
         <span class="classname"><a href="class.mongodb-driver-exception-invalidargumentexception.html" class="classname">MongoDB\Driver\Exception\InvalidArgumentException</a></span>
         is thrown if <code class="parameter">type</code> is
         <strong><code>MongoDB\BSON\Binary::TYPE_UUID</code></strong> or
         <strong><code>MongoDB\BSON\Binary::TYPE_OLD_UUID</code></strong> and
         <code class="parameter">data</code> is not exactly 16 bytes in length.
        </p>
       </td>
      </tr>

      <tr>
       <td>PECL mongodb 1.1.3</td>
       <td>
        <p class="para">
         <span class="classname"><a href="class.mongodb-driver-exception-invalidargumentexception.html" class="classname">MongoDB\Driver\Exception\InvalidArgumentException</a></span>
         is thrown if <code class="parameter">type</code> is not an unsigned 8-bit
         integer.
        </p>
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-mongodb-bson-binary.construct-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-1373">
   <p><strong>示例 #1 <span class="function"><strong>MongoDB\BSON\Binary::__construct()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$binary&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">MongoDB</span><span style="color: #007700">\</span><span style="color: #0000BB">BSON</span><span style="color: #007700">\</span><span style="color: #0000BB">Binary</span><span style="color: #007700">(</span><span style="color: #DD0000">'foo'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">MongoDB</span><span style="color: #007700">\</span><span style="color: #0000BB">BSON</span><span style="color: #007700">\</span><span style="color: #0000BB">Binary</span><span style="color: #007700">::</span><span style="color: #0000BB">TYPE_GENERIC</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$binary</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <div class="example-contents"><p>以上例程会输出：</p></div>
   <div class="example-contents screen">
<div class="cdata"><pre>
object(MongoDB\BSON\Binary)#1 (2) {
  [&quot;data&quot;]=&gt;
  string(3) &quot;foo&quot;
  [&quot;type&quot;]=&gt;
  int(0)
}
</pre></div>
   </div>
  </div>
 </div>



 <div class="refsect1 seealso" id="refsect1-mongodb-bson-binary.construct-seealso">
  <h3 class="title">参见</h3>
  <ul class="simplelist">
   <li class="member"><a href="https://www.mongodb.com/docs/manual/reference/bson-types/" class="link external">&raquo;&nbsp;BSON Types</a></li>
  </ul>
 </div>


</div></div></div></body></html>